<template>
  <div>
     <!-- 查询 -->
    <el-popover placement="bottom-start"  trigger="click">
      <el-form :inline="true" :model="search" label-width="75px" class="search-panle">
        <el-form-item label="浆员卡号" ><el-input v-model="search.cardid"></el-input></el-form-item>
        <el-form-item label="浆员姓名"><el-input v-model="search.name"></el-input></el-form-item>
        <el-form-item label="创建时间" ><el-date-picker v-model="search.time" type="daterange"  range-separator="至" start-placeholder="开始时间" end-placeholder="结束时间" align="right"></el-date-picker></el-form-item>
        <el-button type="primary" @click="searchData">提交</el-button>
      </el-form>
      <el-button slot="reference" type="primary">查询</el-button>
    </el-popover>
    <!-- 表格 -->
    <el-table :data="tableData" stripe border class="company-table" :height="tableHeight" style="width: 100%;">
      <el-table-column prop="registerNo" label="登记序号" sortable min-width="90"></el-table-column>
      <el-table-column prop="cardId" label="卡号" sortable min-width="90"></el-table-column>
      <el-table-column prop="providerNoName" label="姓名" sortable min-width="100"></el-table-column>
      <el-table-column prop="bodyCheckWorkerName" label="体检医生" sortable min-width="110"></el-table-column>
      <el-table-column prop="createNurseName" label="体检护士" sortable min-width="110"></el-table-column>
      <el-table-column prop="registerOrder" label="登记序号" sortable min-width="110"></el-table-column>
      <el-table-column prop="bodyCheckOrder" label="体检序号" sortable min-width="110"></el-table-column>
      <el-table-column prop="authMethod" label="认证方式" :formatter="formatterAuthMethod" sortable min-width="110"></el-table-column>
      <el-table-column prop="bodyStartTime" label="体检开始时间" sortable min-width="170"></el-table-column>
      <el-table-column prop="recodeCreateTime" label="记录创建时间" sortable min-width="170"></el-table-column>
      <el-table-column prop="recodeStatus" label="记录状态" :formatter="formatterIsRecode"  sortable min-width="110"></el-table-column>
      <el-table-column fixed="right" label="操作"  align="center" min-width="75">
          <template slot-scope="scope">
            <el-button  @click="updateDialog(scope.row)" type="text" size="small">编辑</el-button>
          </template>
      </el-table-column>
    </el-table>
    <el-pagination background @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="pagination.currentPage" :page-sizes="[10, 15,20, 25,30,50, 100]" :page-size="pagination.pageSize" layout="total, sizes, prev, pager, next, jumper" :total="pagination.total"></el-pagination>
    <!-- 详情 -->
    <el-dialog :title="dialog.title" :visible.sync="dialog.isShow" width="1100px" top="60px" :close-on-click-modal="false" >
      <div :style="{'height':(tableHeight-90)+'px','overflow-y':'auto'}">
          <h3 class="dialog-plate-title"><span>基本信息</span></h3>
          <!-- 浆员基本信息 -->
          <pulpworkInfo v-bind:cardid="dialogList.providerNo"></pulpworkInfo>
          <h3 class="dialog-plate-title" style="margin-top: 15px;"><span>生命体征</span></h3>
          <el-form :inline="true" :model="dialogList" :rules="dialogRules" ref="dialogRules" label-width="120px" class="demo-ruleForm">
                  <el-form-item label="体重/kg" prop="weight"><el-input v-model="dialogList.weight"></el-input></el-form-item>
                  <el-form-item label="体温/℃" prop="animalHeat"><el-input v-model="dialogList.animalHeat"></el-input></el-form-item>
                  <el-form-item label="脉搏/B/M" prop="pulse"><el-input v-model="dialogList.pulse"></el-input></el-form-item>
                  <el-form-item label="血压/KPa">
                      <el-row style="width: 200px;">
                        <el-col :span="11"><el-form-item prop="lowBlood"><el-input  v-model="dialogList.lowBlood"></el-input></el-form-item></el-col>
                        <el-col class="line" :span="2">-</el-col>
                        <el-col :span="11"><el-form-item prop="highBlood"><el-input  v-model="dialogList.highBlood"></el-input></el-form-item></el-col>
                      </el-row>
                  </el-form-item>
                  <el-form-item label="体检护士"><el-input v-model="dialogList.createNurseName" disabled></el-input></el-form-item>
          </el-form>
          <h3 class="dialog-plate-title" style="margin-top: 15px;"><span>征询项目</span></h3>
          <el-row :gutter="20" style="margin-right: 0;" >
              <el-col :span="8">
                <el-row :gutter="20" style="margin-right: 0;" >
                    <el-col :span="12">
                      <el-upload class="avatar-uploader"
                        ref="appendix"
                        style="height: 230px;"
                        :action="appendixUrl"
                        :show-file-list="false"
                        :on-success="handleAvatarSuccess"
                        :before-upload="beforeAvatarUpload">
                        <img v-if="dialogList.singlePhoto" :src="dialogList.singlePhoto" class="avatar" />
                        <i v-else class="el-icon-plus avatar-uploader-icon"></i>
                      </el-upload>
                    </el-col>
                    <el-col :span="12">
                      <el-upload class="avatar-uploader"
                        style="height: 230px;"
                        :action="appendixUrl"
                        :show-file-list="false"
                        :on-success="handleAvatarSuccess1"
                        :before-upload="beforeAvatarUpload">
                        <img v-if="dialogList.singlePhoto1" :src="dialogList.singlePhoto1" class="avatar" />
                        <i v-else class="el-icon-plus avatar-uploader-icon"></i>
                      </el-upload>
                    </el-col>
                </el-row>
              </el-col>
              <el-col :span="16">
                <el-form :inline="true" :model="dialogList" label-width="100px" class="demo-ruleForm">
                  <el-form-item label="上传时间"><el-input v-model="dialogList.singleUploadTime" ></el-input></el-form-item>
                  <el-form-item label="胸部"><el-select v-model="dialogList.chest" ><el-option :value="1" label="正常"></el-option><el-option :value="0" label="不正常"></el-option></el-select></el-form-item>
                  <el-form-item label="腹部"><el-select v-model="dialogList.abdomen"><el-option :value="1" label="正常"></el-option><el-option :value="0" label="不正常"></el-option></el-select></el-form-item>
                  <el-form-item label="皮肤"><el-select v-model="dialogList.skin"  ><el-option :value="1" label="正常"></el-option><el-option :value="0" label="不正常"></el-option></el-select></el-form-item>
                  <el-form-item label="五官"><el-select v-model="dialogList.facial" ><el-option :value="1" label="正常"></el-option><el-option :value="0" label="不正常"></el-option></el-select></el-form-item>
                  <el-form-item label="四肢"><el-select v-model="dialogList.limbs" ><el-option :value="1" label="正常"></el-option><el-option :value="0" label="不正常"></el-option></el-select></el-form-item>
                  <el-form-item label="健康征询"><el-select v-model="dialogList.healthSingle"><el-option :value="1" label="是"></el-option><el-option :value="0" label="否"></el-option></el-select></el-form-item>
                  <el-form-item label="体检结果"><el-select v-model="dialogList.bodyCheckResult"><el-option value="" label="[空]"></el-option><el-option :value="0" label="不合格"></el-option><el-option :value="1" label="合格"></el-option><el-option :value="2" label="复检"></el-option></el-select></el-form-item>
                  <el-form-item v-if="dialogList.bodyCheckResult=='0'" label="拒绝类型"><el-select v-model="dialogList.refuseType"><el-option :value="0" label="暂拒"></el-option><el-option :value="1" label="永拒"></el-option></el-select></el-form-item>
                  <el-form-item v-if="dialogList.refuseType=='0'" label="暂拒原因"><el-input v-model="dialogList.outReason"></el-input></el-form-item>
                  <el-form-item v-if="dialogList.refuseType=='1'" label="永拒原因"><el-select v-model="dialogList.refuseReason"><el-option v-for="item in codeData2" :key="item.code" :value="item.code" :label="item.name"></el-option></el-select></el-form-item>
                  <el-form-item label="体检医生"><el-select v-model="dialogList.bodyCheckWorker"><el-option  v-for="item in dictorData" :key="item.id" :value="item.id"   :label="item.name"></el-option></el-select></el-form-item>
                </el-form>
              </el-col>
          </el-row>
          <h3 class="dialog-plate-title" style="margin-top: 15px;"><span>其他</span></h3>
          <el-form :inline="true" :model="dialogList" label-width="120px" class="demo-ruleForm">
            <el-form-item label="献浆人"><el-input v-model="dialogList.contributionPerson" disabled></el-input></el-form-item>
            <el-form-item label="登记序号"><el-input v-model="dialogList.registerOrder" disabled></el-input></el-form-item>
            <el-form-item label="体检编号"><el-input v-model="dialogList.bodyCheckNo" disabled></el-input></el-form-item>
            <el-form-item label="体检序号"><el-input v-model="dialogList.bodyCheckOrder" disabled></el-input></el-form-item>
            <el-form-item label="体检开始时间"><el-input v-model="dialogList.bodyStartTime" disabled></el-input></el-form-item>
            <el-form-item label="记录创建时间"><el-input v-model="dialogList.recodeCreateTime" disabled></el-input></el-form-item>
            <el-form-item label="体检结束时间"><el-input v-model="dialogList.bodyEndTime" disabled></el-input></el-form-item>
            <el-form-item label="记录结束时间"><el-input v-model="dialogList.recodeEndTime" disabled></el-input></el-form-item>
            <el-form-item label="记录状态"><el-select v-model="dialogList.recodeStatus" disabled><el-option :value="0" label="待处理"></el-option><el-option :value="1" label="已处理"></el-option></el-select></el-form-item>
          </el-form>
      </div>
      <div slot="footer">
        <el-button type="primary" @click="submitDialog" >提交</el-button>
      </div>
    </el-dialog>
  </div>
</template>
<script>
import api from 'plugins/axios/api.js';
import regx from 'plugins/regx.js';
import pulpworkInfo from 'views/operationManage/components/pulpworkInfo.vue';
export default {
  components:{
      pulpworkInfo
  },
  data(){
    return {
      search:{
        cardid:'',
        name:'',
        time:[]
      },
      tableData:[],
      dictorData:{},
      pagination:{
        currentPage:1,
        pageSize:10,
        total:0
      },
      dialogList:{},
      appendixUrl:"/api/adscm/filesystem/abc",
      dialogRules:{
        weight: [
            { required: true, message: '请输入体重...', trigger: 'blur' },
            {  type: 'number', message: '体重不能高于150Kg，低于45Kg', trigger: 'blur', validator:regx.validateWeight},
          ],
          animalHeat: [
            { required: true, message: '请输入体温...', trigger: 'blur' },
            { type: 'number', message: '体温不能高于37.2 ℃，低于36.3 ℃', trigger: 'blur',validator:regx.validateAnimalHeat }
          ],
          pulse: [
            { required: true, message: '请输入脉搏...', trigger: 'blur' },
            { type: 'number', message: '脉搏不能高于100/B/M，低于60/B/M', trigger: 'blur',validator:regx.validatePulse},
          ],
          lowBlood: [
            { required: true, message: '请输入低血压...', trigger: 'blur' },
            { type: 'number', message: '低压不能高于8/KPa，低于12/KPa', trigger: 'blur',validator:regx.validateLowBlood},
          ],
          highBlood: [
            { required: true, message: '请输入高血压...', trigger: 'blur' },
            { type: 'number', message: '高压不能高于12/KPa，低于20/KPa', trigger: 'blur',validator:regx.validateHighBlood},
          ],
      },
      dialog:{
        title:'',
        isShow:false
      }
    }
  },
  created(){
    this.getData();
  },
  computed:{
    tableHeight(){
      return this.$store.state.clientHeight-184;
    }
  },
  methods:{
    getData(){//获取体检记录列表
      let self = this;
      self.loading=true;
      let list={
          name:self.search.name,
          cardid:self.search.cardid,
          recodeTime:self.timestampToTime(new Date,'yy-mm-dd'),
          pageSize:self.pagination.pageSize,
          currentPage:self.pagination.currentPage
      }
      if(self.search.time.length>0){
        list.bigCreateTime = self.timestampToTime( self.search.time[0],'yy-mm-dd');
        list.lessCreateTime=self.timestampToTime( self.search.time[1],'yy-mm-dd');
      }
      api.bodyCheckTime(list).then(res=>{
          self.tableData=res.content.items;
          self.loading=false;
          self.pagination.total = res.content.total;
      },error=>{
            self.loading=false;
      })

    },
    /**新版页面数据功能补全 __by:zf */
    getDoctorData(){//获取医生列表
      let self = this;
      self.loading=true;
      api.getDoctorData({id:4}).then(res=>{
        self.dictorData = res.content;
        self.loading=false;
        /**↓ 此处联动 self.updateDialog 方法 Number转换 如果该血源没有医生，则默认所有医生列表中的第一个 ↓*/
        if(self.dialogList.bodyCheckWorker==0){
          console.log(self.dialogList.bodyCheckWorker==0);
          self.dialogList.bodyCheckWorker=self.dictorData[0].id;
        }
      },error=>{
            self.loading=false;
      })
    },
    submitDialog(){/** 更新后台信息*/
      let self = this;
      self.loading=true;
      api.addUpdataCheckBodyInfo(self.dialogList).then(res=>{
        self.loading=false;
        self.dialog.isShow=false;
        self.$message.success('信息编辑成功！');
        self.getData();
        self.dialog1.isShow = false;
      },error=>{
            self.loading=false;
      })

     },
    searchData(){/**搜索提交 */
      this.pagination.currentPage=1;
      this.getData();
    },
    updateDialog(row){/**点击编辑*/
      let self = this;
      self.dialog.title = '详情信息';
      self.dialog.isShow = true;
      self.dialogList = row;
      self.dialogList.bodyCheckWorker=Number(self.dialogList.bodyCheckWorker);
      self.getDoctorData();
    },
    handleSizeChange(size){/**改变分页条数 */
      this.pagination.currentPage=1;
      this.pagination.pageSize = size;
      this.getData();
    },
    handleCurrentChange(current){/**改变分页页码 */
       this.pagination.currentPage=current;
      this.getData();
    },
    beforeAvatarUpload(file){/**图标上传前尺寸大小判断 */
      const isJPG = file.type.substr(0,5) === 'image';
      const isLt1M = file.size / 1024 / 1024 < 1;
      if (!isJPG) {
          this.$message.error('只能上传图片!');
      }
      if (!isLt1M) {
          this.$message.error('上传头像图片大小不能超过 1MB!');
      }
      return isJPG && isLt1M;
    },
    handleAvatarSuccess(res,file,fileList){},
    handleAvatarSuccess1(res,file,fileList){},
  }
}
</script>
<style lang="stylus" scoped>

</style>


